<template>
  <div class="contain">
    <h1 style="margin-top: 80px;color: white;">注册</h1>
    <div class="minputcontain">
      <x-input class="minput" v-model="login_name" type="text" placeholder="请输入账号"></x-input>
      <x-input class="minput" v-model="login_psw" type="password" placeholder="请输入密码"></x-input>
      <x-input class="minput" v-model="psw_confirm" type="password" placeholder="请确认密码"></x-input>
      <x-button class="btn_login" type="primary" @click.native="register">注册</x-button>
    </div>

    <alert v-model="showdialog" :content="dialog_content"></alert>
  </div>
</template>

<script>

  import XInput from "vux/src/components/x-input/index";
  import XButton from "vux/src/components/x-button/index";
  import Alert from "../../node_modules/vux/src/components/alert/index.vue";

  export default {
    name: "Login",
    data() {
      return {
        login_name: "",
        login_psw: "",
        psw_confirm: "",
        showdialog: false,
        dialog_content:''
      }
    },
    methods: {
      register() {
        var vm = this;
        this.$http.post('/v1/users/register',
          {
            username: this.login_name,
            password: this.login_psw,
            cpassword: this.psw_confirm
          }
        ).then(function (response) {
          if (response.data.code === 1003) {
            vm.$vux.toast.text('用户已存在','middle')
          } else {
            if (response.data.code === 1000) {
              vm.$vux.toast.text('注册成功','middle')
              vm.$router.replace('/login')
            } else {
              vm.$vux.toast.text(response.data.message,'middle')
            }
          }
        }).catch(function (e) {
          console.log(e.data)
        })
      },
      btn_register(){
        this.$router.push()
      }
    },
    components: {
      Alert,
      XButton, XInput},
  }
</script>
<style scoped>
  .contain {
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    background: url("../assets/login_bg3.jpg") no-repeat;
    background-size: 100% 100%;
    text-align: center;
  }

  .minput {
    border: none;
    background: #ebf5dd;
    margin-top: 20px;
    border-radius: 4px;
  }

  .btn_login {
    border-radius: 4px;
    margin-top: 30px;
  }

  .minputcontain {
    text-color: 'white';
    margin: 20px;
    margin-top: 100px;
    box-sizing: border-box;
  }

</style>
